package com.sskj.mine.asset;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.asset.data.RechargeTypeBean;
import com.sskj.mine.asset.data.WithdrawConfigBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.BasePresenter;
import com.sskj.mine.asset.WithdrawActivity;

import java.util.List;


/**
 * @author Hey
 * Create at  2019/05/04
 */
class WithdrawPresenter extends BasePresenter<WithdrawActivity> {


    /**
     * 提币页面
     *
     * @param pid 币种ID
     * @return
     */
    public void getWithdrawConfig(String pid) {
        httpService.getWithdrawConfig(pid).execute(new JsonCallBack<HttpData<WithdrawConfigBean>>() {
            @Override
            public void onSuccess(Response<HttpData<WithdrawConfigBean>> response) {
                HttpData<WithdrawConfigBean> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    mView.updateUI(httpData.getData());
                }
            }
        });
    }

    public void sendSms(String account) {
        httpService.sendSms(account, "3")
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.sendCheckCodeSuccess();
                        }else {
                            mView.sendCheckCodeFail();

                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        mView.sendCheckCodeFail();
                        super.onError(response);
                    }
                });
    }

    /**
     * 提币
     *
     * @param num     数量
     * @param pid     币id
     * @param tpwd    交易密码
     * @param code    code
     * @param account 手机号/邮箱号
     * @param address 地址
     * @return
     */
    public void withdraw(String num, String pid, String tpwd, String code, String account, String address) {
        httpService.withdraw(num, pid, tpwd, code, account, address).execute(new JsonCallBack<HttpData>() {
            @Override
            public void onSuccess(Response<HttpData> response) {
                HttpData httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {

                }
            }
        });
    }

    public void getType() {
        httpService.withdrawList()
                .execute(new JsonCallBack<HttpData<List<RechargeTypeBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<RechargeTypeBean>>> response) {
                        HttpData<List<RechargeTypeBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.updateType(httpData.getData());
                        }
                    }
                });
    }
}
